import { hp } from '@/utils/util'

const SERVER_PATH = process.env.NUXT_SERVER_PATH
const SERVER_PORT = process.env.NUXT_SERVER_PORT
const BASEURL = SERVER_PATH === 'localhost' ? `http://${SERVER_PATH}:${SERVER_PORT}` : ''

export default $axios => auth => ({

  updateNewUserPassword (params) {
    return $axios.$post(`${BASEURL}${auth}/resetPassword`, hp(params))
  },

  getRolesByPage (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}${auth}/role/search?pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  },

  getRoles () {
    return $axios.$post(`${BASEURL}${auth}/role/searchAll?`)
  },

  addRole (params) {
    return $axios.$post(`${BASEURL}${auth}/role`, hp(params))
  },

  updateRole (id, params) {
    return $axios.$put(`${BASEURL}${auth}/role/${id}`, hp(params))
  },

  delRole (id) {
    return $axios.$delete(`${BASEURL}${auth}/role/${id}`)
  },

  updateUser (id, params) {
    return $axios.$put(`${BASEURL}${auth}/user/${id}`, hp(params))
  },

  updateUserWithDetail (id, params) {
    return $axios.$put(`${BASEURL}${auth}/userWithDetail/${id}`, hp(params))
  },

  updatePassword (params) {
    return $axios.$post(`${BASEURL}${auth}/simpleUpdatePassword`, hp(params))
  },

  resetPassword (params) {
    return $axios.$post(`${BASEURL}${auth}/simpleResetPassword`, hp(params))
  },

  getUser (id) {
    return $axios.$get(`${BASEURL}${auth}/${id}`)
  },

  delUser (id) {
    return $axios.$delete(`${BASEURL}${auth}/user/${id}`)
  },

  saveUser (params) {
    return $axios.$post(`${BASEURL}${auth}/saveUser`, hp(params))
  },

  saveUserForm (params) {
    return $axios.$post(`${BASEURL}${auth}/saveUserForm`, hp(params))
  },

  toggleUser (param) {
    return $axios.$post(`${BASEURL}${auth}/user/toggle`, hp(param))
  },

  queryUserRole (userid) {
    return $axios.$post(`${BASEURL}${auth}/user/queryUserRole/${userid}`)
  },

  getPermissions (params) {
    return $axios.$get(`${BASEURL}${auth}/getPermissions`, hp(params))
  },

  getUserByPages (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}${auth}/search?pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  },
  queryDepartTreeList (params) {
    return $axios.$get(`${BASEURL}${auth}/sysDepart/queryTreeList`, hp(params))
  },
  searchByKeywords (keyWord) {
    return $axios.$get(`${BASEURL}${auth}/sysDepart/searchBy?keyWord=${keyWord}`)
  },
  deleteByDepartId (id) {
    return $axios.$delete(`${BASEURL}${auth}/sysDepart/delete/${id}`)
  },
  queryIdTree (id) {
    return $axios.$get(`${BASEURL}${auth}/sysDepart/queryIdTree`)
  },
  addDept (params) {
    return $axios.$post(`${BASEURL}${auth}/sysDepart/add`, params, { headers: { 'content-type': 'application/json' }})
  },
  editDept (params) {
    return $axios.$put(`${BASEURL}${auth}/sysDepart/edit`, hp(params))
  },
  deleteDepartBatch (ids) {
    return $axios.$delete(`${BASEURL}${auth}/sysDepart/deleteBatch?ids=${ids}`)
  },

  checkUsername (params) {
    return $axios.$get(`${BASEURL}${auth}/checkUsername`, hp(params))
  },

  editUDepartIds (params) {
    return $axios.$put(`${BASEURL}${auth}/sysUser/editUDepartIds`, params, { headers: { 'content-type': 'application/json' }})
  },

  getDepartUserList (params) {
    return $axios.$get(`${BASEURL}${auth}/sysUser/departUserList?` + hp(params))
  },

  getUserWithDepart (params) {
    return $axios.$get(`${BASEURL}${auth}/sysUser/userDepartList?` + hp(params))
  },

  deleteUserInDepart (deptId, userId) {
    return $axios.$delete(`${BASEURL}${auth}/sysUser/deleteUserInDepart?depId=${deptId}&userId=${userId}`)
  },

  deleteUserInDepartBatch (deptId, userIds) {
    return $axios.$delete(`${BASEURL}${auth}/sysUser/deleteUserInDepartBatch?depId=${deptId}&userIds=${userIds}`)
  }
})
